from django.db import models

from user.models import UserModels
from utils.BaseModel import BaseModel


# Create your models
class CouponModel(BaseModel):
    name=models.CharField(max_length=50,verbose_name="优惠卷名称")
    price=models.DecimalField(max_digits=10,decimal_places=2,verbose_name="优惠卷金额")
    condition=models.DecimalField(max_digits=10,decimal_places=2,verbose_name="满减条件")
    start_time=models.DateTimeField(verbose_name="开始时间")
    end_time=models.DateTimeField(verbose_name="结束时间")
    class Meta:
        db_table='fgcoupon'
    def __str__(self):
        return self.name

class UserCouponModel(BaseModel):
    user=models.ForeignKey(UserModels,on_delete=models.CASCADE,verbose_name="用户")
    coupon=models.ForeignKey(CouponModel,on_delete=models.CASCADE,verbose_name="优惠卷")
    class Meta:
        db_table='usercoupon'


# 订单
class OrderModel(BaseModel):
    user=models.ForeignKey(UserModels,on_delete=models.CASCADE,verbose_name="用户")
    orderno=models.CharField(max_length=50,verbose_name="订单号")
    totalprice=models.DecimalField(max_digits=10,decimal_places=2,verbose_name="订单金额")
    realprice=models.DecimalField(max_digits=10,decimal_places=2,verbose_name="实际支付金额")
    paytype=models.IntegerField(choices=((0,"支付宝"),(1,"微信"),(2,"银行卡")),verbose_name="支付方式")
    paytime=models.DateTimeField(verbose_name="支付时间",null=True,blank=True)
    status=models.IntegerField(default=0,choices=((0,"待支付"),(1,"已支付"),(2,"已取消"),(3,"已平均")),verbose_name="订单状态")
    score=models.IntegerField(verbose_name="使用积分",null=True,blank=True)
    coupon=models.IntegerField(null=True,blank=True,verbose_name="使用优惠券")
    payno=models.CharField(max_length=50,verbose_name="支付流水线",null=True,blank=True)
    class Meta:
        db_table='fgorder'
    def __str__(self):
        return self.orderno

# 订单详细
class OrderDatailModel(BaseModel):
    order=models.ForeignKey(OrderModel,on_delete=models.CASCADE,verbose_name="订单")
    courseid=models.IntegerField(verbose_name="课程id")
    coursename=models.CharField(max_length=50,verbose_name="课程名称")
    courseprice=models.DecimalField(max_digits=10,decimal_places=2,verbose_name="课程价格")
    cover=models.CharField(max_length=200,verbose_name="课程封面")
    type=models.IntegerField(verbose_name="课程名称")
    class Meta:
        db_table='fgorderdeail'
# 用户购买的课程表
class goumai(BaseModel):
    userid=models.CharField(max_length=10,verbose_name="用户ID")
    Courseid=models.CharField(max_length=10,verbose_name="课程ID")
    class Meta:
        db_table='fggoumai'

